package cn.edu.cdu.argorithm.impl;

import cn.edu.cdu.argorithm.ISwapNodesInPairs;
import cn.edu.cdu.argorithm.common.ListNode;

public class SwapNodesInPairsSolutions {
    public static class Solution implements ISwapNodesInPairs {
        @Override
        public ListNode swapPairs(ListNode head) {
            ListNode dummyHead = new ListNode(Integer.MIN_VALUE, head), prev = dummyHead, curr = dummyHead.next;
            while(curr != null && curr.next != null) {
                ListNode next = curr.next;
                curr.next = curr.next.next;
                next.next = curr;
                prev.next = next;
                prev = curr;
                curr = prev.next;
            }
            return dummyHead.next;
        }
    }
}
